﻿using System.Windows.Forms;
using System.Collections;
using System.Linq;
using System;

namespace FTTXImportUtility.Utility
{
    static class ComboBoxUtility
    {
        public static void SetDataSource(this ComboBox comboBox, ICollection collection)
        {
            comboBox.BeginUpdate();

            ArrayList arrList = new ArrayList(collection);

            comboBox.Items.AddRange(arrList.ToArray());
            
            comboBox.EndUpdate();
        }

        public static void SetDataSource(this ComboBox comboBox, ICollection collection, string displayMember, string valueMember)
        {
            SetDataSource(comboBox, collection);
            comboBox.DisplayMember = displayMember;
            comboBox.ValueMember = valueMember;
        }

        public static void SetDataSource(this ComboBox comboBox, ICollection collection, string displayMember, string valueMember, bool AppendIems)
        {
            if (!AppendIems) comboBox.Items.Clear();
            SetDataSource(comboBox, collection);
            comboBox.DisplayMember = displayMember;
            comboBox.ValueMember = valueMember;
        }
    }
}
